package com.loong.nnm;

import com.alibaba.fastjson.JSONObject;
import com.loong.nnm.entity.netconf.NetconfBuilderParameters;
import com.loong.nnm.impl.NetconfToolImpl;
import com.loong.nnm.services.NetconfToolServices;
import com.loong.nnm.utils.NetconfProtocolUtils;
import com.loong.nnm.utils.PrettyJSON;
import com.loong.nnm.utils.XMLToJsonUtils;
import net.juniper.netconf.XML;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;

public class MyTestForNetconf {

    @Resource
    NetconfProtocolUtils netconfProtocolUtils;

    @Resource
    NetconfToolImpl netconfTool;

    @Autowired
    NetconfToolServices services;

    @Test
    public void notification() {

        String testStr = "<get>\n" +
                "        <filter type=\"subtree\">\n" +
                "            <netconf xmlns=\"urn:ietf:params:xml:ns:netmod:notification\">\n" +
                "                <streams/>\n" +
                "            </netconf>\n" +
                "        </filter>\n" +
                "    </get>";

    }

    @Test
    public void test(){
        netconfTool.createConnection(new NetconfBuilderParameters("192.168.11.60","root","dfqxyfy",830));
        String test =   "      <edit-config>\n"+
                "  <target>\n"+
                "    <running/>\n"+
                "  </target>\n"+
                "  <config>\n"+
                "    <alarm-mask-states xmlns=\"urn:ccsa:yang:acc-alarms\">\n"+
                "      <alarm-mask-state>\n"+
                "        <object-name>EH=/shelf=1/slot=1/EQ=PWDC</object-name>\n"+
                "        <alarm-code>OVER_BRD_TMP</alarm-code>\n"+
                "        <object-type>EQ</object-type>\n"+
                "        <mask-state>true</mask-state>\n"+
                "      </alarm-mask-state>\n"+
                "    </alarm-mask-states>\n"+
                "  </config>\n"+
                "</edit-config>";

        System.out.println(netconfProtocolUtils.send(test));
    }

    String test =   "      <edit-config>\n"+
            "  <target>\n"+
            "    <running/>\n"+
            "  </target>\n"+
            "  <config>\n"+
            "    <alarm-mask-states xmlns=\"urn:ccsa:yang:acc-alarms\">\n"+
            "      <alarm-mask-state>\n"+
            "        <object-name>EH=/shelf=1/slot=1/EQ=PWDC</object-name>\n"+
            "        <alarm-code>OVER_BRD_TMP</alarm-code>\n"+
            "        <object-type>EQ</object-type>\n"+
            "        <mask-state>true</mask-state>\n"+
            "      </alarm-mask-state>\n"+
            "    </alarm-mask-states>\n"+
            "  </config>\n"+
            "</edit-config>";

    String test1 = "<get>\n" +
            "<filter type=\"subtree\">\n" +

            "<ptps xmlns=\"urn:ccsa:yang:acc-devm\">\n" +
            "<ptp>PTP=/shelf=1/slot=6/port=101</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=102</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=103</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=104</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=105</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=106</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=107</ptp>\n" +
            "        <ptp>PTP=/shelf=1/slot=6/port=108</ptp>\n" +
            "        <ftp>FTP=/shelf=1/slot=6/port=201</ftp>\n"+
            "</ptps>\n" +
            "</filter>\n" +
            "</get>";
    @Test
    public void testXMLToJson(){
        services.createConnection(new NetconfBuilderParameters("192.168.11.60","root","dfqxyfy",830));
        String send = "<get>\n" +
                "<filter type=\"subtree\">\n" +

                "<ptps xmlns=\"urn:ccsa:yang:acc-devm\">\n" +
                "</ptps>\n" +
                "</filter>\n" +
                "</get>";
        XML send1 = netconfProtocolUtils.send(send);
        try {
            JSONObject object = XMLToJsonUtils.xmlToJson(send1.toString());
//            JSONObject filter = object.getJSONObject("get").getJSONObject("filter");
            System.out.println("=========================================");
            System.out.println(PrettyJSON.pretty(object.toString()));
            System.out.println("=========================================");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
